package com.example.big_orange2.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.example.big_orange2.common.Result;
import com.example.big_orange2.entity.Staff;
import com.example.big_orange2.entity.lockrule;
import com.example.big_orange2.mapper.StaffMapper;
import com.example.big_orange2.mapper.lockruleMapper;
import com.example.big_orange2.service.LockRuleService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/lockrule")
public class lockruleController {
    @Resource
    lockruleMapper lockruleMapper;
    @Resource
    LockRuleService lockRuleService;
    //增
    //向数据库写入（insert）数据的接口
    @PostMapping("/add")
    public Result<?> save(@RequestBody lockrule lockrule){//?是泛型，表示任意类型
        //设置默认值
        //插入的操作
        lockruleMapper.insert(lockrule);
        return Result.success();//返回操作情况
    }
    //向数据库删除（delete）数据的接口
    @DeleteMapping("/delete/{lockclassid}")//占位
    public Result<?> delete(@PathVariable String lockclassid){//?是泛型，表示任意类型
        //删除的操作
        lockruleMapper.deleteById(lockclassid);
        return Result.success();//返回操作情况

    }
    //修改功能
    @PutMapping("/update")
    //向数据库更新（update）数据的接口
    public Result<?> update(@RequestBody lockrule lockrule){//?是泛型，表示任意类型
        lockruleMapper.updateById(lockrule);
        return Result.success();
    }

    //全部查询
    @GetMapping("/getdata")
    //根据员工号，挑选他负责的客户信息
    public Result<?> finduser(){
        LambdaQueryWrapper<lockrule> wrapper = Wrappers.<lockrule>lambdaQuery();
        List<lockrule> Loanhandle = lockruleMapper.selectList(wrapper);//
        return  Result.success(Loanhandle);//返回结果

    }

    //依据用户id查询
    @GetMapping("/getdata/{lockclassid}")
    //根据员工号，挑选他负责的客户信息
    public Result<?> findoneuser(@PathVariable String lockclassid){
        LambdaQueryWrapper<lockrule> wrapper =Wrappers.<lockrule>lambdaQuery();
        wrapper.eq(lockrule::getLockclassid,lockclassid);//多条件查询
        List<lockrule> Loanhandle = lockruleMapper.selectList(wrapper);//
        return  Result.success(Loanhandle);//返回结果

    }
    //获取押金
    @GetMapping("/getdeposit/{sharelockid}")
    //根据员工号，挑选他负责的客户信息
    public Result<?> getdeposit(@PathVariable int sharelockid){
       float result= lockruleMapper.getdeposit(sharelockid);
        return  Result.success(result);
    }

    @PostMapping("/paging/{page}/{limit}")
    //分页查询(select),查询数据接口
    public Result<?> findPage(@PathVariable Integer page,
                              @PathVariable Integer limit,
                              @RequestBody(required = false)  String s
    ){
        Result<?> result=new Result<>();
        result= lockRuleService.findPage(page,limit,s);
        return  result;

    }
}
